package cn.z2huo.knowledge.streamapi.collectors;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 *
 * @author z2huo
 */
class CollectorsToMapTest {

    public static void main(String[] args) {

        List<Student> students = List.of(
                new Student("zyz", 12, "42", "20164238"),
                new Student("zyf", 10, "42", "20164222"),
                new Student("zys", 11, "42", "20164211")
        );

        Map<String, Student> collect = students.stream().collect(Collectors.toMap(Student::getStudentId, t -> t));
        System.out.println(collect.keySet());
        System.out.println(collect.values());
        System.out.println(collect.entrySet());

        Map<String, String> nameMap = students.stream().map(Student::getName).distinct().collect(Collectors.toMap(name -> name, name -> ""));
        System.out.println(nameMap);

        Map<String, String> nameMap2 = students.stream().collect(Collectors.toMap(Student::getName, student -> null, (v1, v2) -> v1));
        System.out.println(nameMap2);

    }

}
